#include<GenerateInit.h>


QString GenerateInit()
{
    //选取主词条

    QString Maintype;
    QString Mainstr;
    QList<int> weight1;
    GenWeightList("dataMain",weight1);
    int tmpRndID1=IndexWithWeight(weight1);
    Maintype= ReadStrWt("dataMain","圣遗物类型",tmpRndID1);
    Mainstr= ReadStrWt("dataMain","圣遗物主词条",tmpRndID1);

    //选取副词条

    QString SubstrDist[4];

    for(int i=0;i<4;i++)
    {
        QList<int> weight2;
        GenWeightList(InitMap(Mainstr),weight2);
        int tmpRndID2=IndexWithWeight(weight2);
        SubstrDist[i]=ReadStrWt(InitMap(Mainstr),"副词条类型",tmpRndID2);
        bool flag=true;
        for(int j=0;j<i;j++)
        {
            if(SubstrDist[i]==SubstrDist[j])
            {
                flag=false;
                break;
            }
        }
        if(flag==false)
        {
            i=i-1;
        }
    }

    //读取副词条成长值,写入初始值

    float InitValue[4]={0,0,0,0};
    for(int i =0;i<4;i++)
    {
        InitValue[i]=ReadGrowth(SubstrDist[i]);
    }
    int rand = QRandomGenerator::global()->generate()%5;
    if(rand>0)
        InitValue[3]=0;
    QUuid id = QUuid::createUuid();
    QString StrId=id.toString();
    QSqlQuery Query;
    QString Insert("insert into List values (?, ?, ?, ?,?, ?,?,?,?,?,?,?)");
    Query.prepare(Insert);
    Query.addBindValue(Maintype);
    Query.addBindValue(Mainstr);
    Query.addBindValue(SubstrDist[0]);
    Query.addBindValue(SubstrDist[1]);
    Query.addBindValue(SubstrDist[2]);
    Query.addBindValue(SubstrDist[3]);
    Query.addBindValue(InitValue[0]);
    Query.addBindValue(InitValue[1]);
    Query.addBindValue(InitValue[2]);
    Query.addBindValue(InitValue[3]);
    Query.addBindValue(StrId);
    Query.addBindValue(0);
    Query.exec();
    return(StrId);

}
